import java.awt.Component;
import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLayer;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.plaf.LayerUI;

/**
 * 
 */

/**
 * @author Clara Yael Bradichansky
 *
 */
public class MyLayerUI extends LayerUI<Component> {
	static JTextField txt;	
	/* (non-Javadoc)
	 * @see javax.swing.plaf.LayerUI#paint(java.awt.Graphics, javax.swing.JComponent)
	 */
	@Override
	public void paint(Graphics g, JComponent c) {
		
		try {
			c.getParent().paint(g);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		super.paint(g, c);
		g.setClip(0,0,c.getWidth()+80,c.getHeight()+10);
		if(!txt.getText().equals(""))
			g.drawLine(0, 0, c.getWidth(), c.getHeight());
		//System.out.println(g.clipRect(x, y, width, height));

		g.dispose();
	}
	
	public static void main(String[] args) {
		JFrame f = new JFrame("my window");
		txt = new JTextField();
		txt.setColumns(30);
		JPanel p = new JPanel();
		p.add(txt);
		f.add(new JLayer<Component>(p,new MyLayerUI()));
		f.pack();
		f.setVisible(true);
	}

}
